<template>
  <div class="column-detail-page w-75 mx-auto">
    <div class="column-info row mb-4 border-bottom pb-4 align-items-center">
      <div class="col-3 text-center">
        <img :src="`${column.avatar}?x-oss-process=image/resize,m_pad,h_100,w_100`" alt="column.title" class="rounded-circle border w-100">
      </div>
      <div class="col-9">
        <h4>{{ column.title }}</h4>
        <p class="text-muted">
          {{ column.description }}
        </p>
      </div>
    </div>
    <post-list :list="list"></post-list>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { useRoute } from 'vue-router' // 在页面中使用路由参数
import PostList from '../../components/PostList.vue'
import { useStore } from 'vuex'
import { GlobalDataProps } from '../../store'
export default defineComponent({
  name: 'Column',
  components: {
    PostList
  },
  setup () {
    // 获取页面的路由
    const route = useRoute()
    const store = useStore<GlobalDataProps>()
    const currentId = +route.params.id // 获取当前的id
    const column = store.state.columns.find(c => c.id === currentId) // 根据id获取专栏的list
    const list = store.state.posts.filter(post => post.columnId === currentId)
    return {
      column,
      list
    }
  }
})
</script>
